﻿using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using TrackSystem.Entities.Extensions;

namespace TrackSystem.Entities.Models
{
    /// <summary>
    /// 通道记录表
    /// </summary>
    [Table("channel")]
    public class ChannelTable
    {
        /// <summary>
        /// 统一标识符
        /// </summary>
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Display(Name="统一标识符")]
        public int Id { get; set; }

        /// <summary>
        /// 通道名称
        /// </summary>
        [Required]
        [Display(Name = "通道名称")]
        public string Name { get; set; }

        /// <summary>
        /// 通道描述
        /// </summary>
        public string? Description { get; set; }

        /// <summary>
        /// 端口通信种类
        /// </summary>
        public PortCategory PortCategory { get; set; }

        /// <summary>
        /// 通道远程IP地址
        /// </summary>
        public string? Ip { get; set; }

        /// <summary>
        /// 远程通道端口地址
        /// </summary>
        public int Port { get; set; }

        /// <summary>
        /// UDP通信方式， 需要知道本地IP地址
        /// </summary>
        public string? localIp { get; set; }

        /// <summary>
        /// UDP通信方式，需要知道本地通信端口号
        /// </summary>
        public int localPort { get; set; }

        /// <summary>
        /// 串口通信方式，需要知道本地的通讯串口号
        /// </summary>
        public  string? COMn { get; set; }

        /// <summary>
        /// 通信波特率
        /// </summary>
        public int Baudrate { get; set; }

        /// <summary>
        /// 串口参数，类似 “N-8-1”
        /// </summary>
        public string? SerialParams { get; set; }

        /// <summary>
        /// 通信协议
        /// </summary>
        public ProtocolEnum Protocol { get; set; }

        /// <summary>
        /// 在MODBU协议下，是否支持21功能
        /// </summary>
        public bool optSupport21Cmd { get; set; }

        /// <summary>
        /// 在MODBU协议下，是否支持3/4功能分离
        /// </summary>
        public bool optSplit3_4Cmd { get; set; }

        /// <summary>
        /// 通信周期 ms
        /// </summary>
        public int Interval { get; set; }

        /// <summary>
        /// 挂接的传感器
        /// </summary>
        public ICollection<SensorTable>? Sensors { get; set; }
    }
}
